package com.ecy.quadratic.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ecy.quadratic.R;
import com.ecy.quadratic.beans.Video;

import java.util.List;

public class VideoOneThirdAdapter extends BaseAdapter {

    private List<Video> mComicList;
    private Context mContext;
    private int mCount = 0;
    private int MAX_COUNT = 100;

    public VideoOneThirdAdapter(Context context, List<Video> comicList) {
        mContext = context;
        mComicList = comicList;
    }

    public VideoOneThirdAdapter(Context context, List<Video> comicList, int limitSize) {
        mContext = context;
        mComicList = comicList;
        MAX_COUNT = limitSize;
    }


    @Override
    public int getCount() {
        mCount = mComicList == null ? 0 : mComicList.size();

        return Math.min(mCount, MAX_COUNT);
    }

    @Override
    public Video getItem(int position) {
        if (mComicList != null) {
            return mComicList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.recommend_grid_onethird_item, null);
            viewHolder = new ViewHolder();
            viewHolder.recommendTitleTV = (TextView) convertView.findViewById(R.id.recommend_grid_title_tv);
            viewHolder.recommendSectionTV = (TextView) convertView.findViewById(R.id.recommend_grid_section_tv);
            viewHolder.recommendCoverIV = (ImageView) convertView.findViewById(R.id.recommend_grid_item_iv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.recommendSectionTV.setVisibility(View.GONE);
        Video comic = getItem(position);
        viewHolder.recommendTitleTV.setText(comic.getTitle());
//		viewHolder.recommendSectionTV.setText(comic.getShort_description());
        System.out.println(comic.getImg());
        Glide.with(mContext).load(comic.getImg()).placeholder(R.drawable.cover_default).centerCrop().into(viewHolder.recommendCoverIV);
        return convertView;
    }

    public class ViewHolder {
        public TextView recommendTitleTV;
        public TextView recommendSectionTV;
        public ImageView recommendCoverIV;
    }

}
